import React, {Component} from 'react';
import {
    View,
    TouchableOpacity,
    StyleSheet,
    Image,
    Dimensions
} from 'react-native'
import Button                        from 'apsl-react-native-button';
import GlobalStyle                   from '../utils/GlobalStyle';
import ScreenUtil                    from "../utils/ScreenUtils";
import StorageUtil                   from "../utils/StorageUtil";
import { NavigationActions,StackActions } from 'react-navigation'
const {width,height} = Dimensions.get('window');

const resetMyAccountTab = StackActions.reset({
    index: 0,
    actions: [
        NavigationActions.navigate({routeName: 'Main',
            action: NavigationActions.navigate({ routeName: 'Main'})
        }),
    ]
})


export default class LoginScreen extends Component {


    componentWillMount() {

        // 判断是否已登录
        StorageUtil.get('hasLogin', (error, object) => {
            if (!error && object != null) {
                //执行重置路由方法
                console.log('点击数据----',object);

                this.props.navigation.dispatch(resetMyAccountTab)
            }
        });
    }

    goLogin(){
        StorageUtil.set('hasLogin',{'hasLogin':true});

        global.token=
            'UiDX3qVRCk8KmTnMSPXKqLU7QotemkiImnJrWWuAp9Bq28GpdLFTZzb7sMTT6x5pl0uCsldWyKFzgOXcFgdSkg!!';

        this.props.navigation.dispatch(resetMyAccountTab)
    }

    render() {
        return (
            <View style={styles.container}>

                <Image source={require('../../res/images/login/pic_logo.png')}
                       style={styles.logoStyle}/>

                <Button
                    allowFontScaling={false}
                    activeOpacity={1}
                    style={GlobalStyle.btnViewStyle} textStyle={GlobalStyle.btnTextStyle}
                    onPress={()=>this.goLogin()}>
                    立即登录
                </Button>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor:'white',
        alignItems:'center'
    },
    logoStyle:{
        height:ScreenUtil.scaleSize(284),
        width:ScreenUtil.scaleSize(247),
        marginTop:height/5,
        // resizeMode:Image.resizeMode.contain
    }
});
